package javacafe.action.studybbs;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javacafe.action.Action;
import javacafe.action.ActionForward;
import javacafe.dto.studybbs.StudyBBSDTO;
import javacafe.service.StudyBBSService;
import javacafe.serviceimple.StudyBBSServiceImpl;

public class UpdateBBSAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		//ActionForward
		ActionForward forward = new ActionForward();
		forward.setTiles(false);
		
		int study_no = Integer.parseInt(request.getParameter("study_no"));
		forward.setUrl( "studybbs?command=bbsmgr&study_no=" + study_no );
		
		//getParameter
		String sbbs_title = request.getParameter("sbbs_title");
		String sbbs_content = request.getParameter("sbbs_content");
		int sbbs_delflag = Integer.parseInt(request.getParameter("sbbs_delflag") == null ? "0" : "1");
		int sbbs_no = Integer.parseInt(request.getParameter("sbbs_no"));
		StudyBBSDTO dto = new StudyBBSDTO();
		dto.setSbbs_title(sbbs_title);
		dto.setSbbs_content(sbbs_content);
		dto.setDelflag(sbbs_delflag);
		dto.setStudy_no(study_no);
		dto.setSbbs_no(sbbs_no);
		
		//studybbsService
		StudyBBSService studyBBSService = StudyBBSServiceImpl.getInstance();
		studyBBSService.updateBBS(dto);
		
		return forward;
	}

}
